package l1j.server.server;

import java.util.HashSet;
import java.util.Set;

import l1j.server.server.utils.TimeUtil;

public class ShutdownTimer implements Runnable {
	public void run() {
		for (ShutdownTime s : _allShutdownTime) {
			if (s.hour == TimeUtil.Hour24() && s.minute == TimeUtil.Minute()) {
				GameServer.getInstance().shutdownWithCountdown(300);
				_allShutdownTime.clear();
				break;
			}
		}
	}

	public static void initilize() {
		GeneralThreadPool.getInstance().scheduleAtFixedRate(_instance, 0,
				60 * 1000);
	}

	private static ShutdownTimer _instance = new ShutdownTimer();

	private static Set<ShutdownTime> _allShutdownTime = new HashSet<ShutdownTime>();

	public static void addShutdownTime(int hour, int minute) {
		_allShutdownTime.add(_instance.new ShutdownTime(hour, minute));
	}

	class ShutdownTime {
		ShutdownTime(int h, int m) {
			hour = h;
			minute = m;
		}

		int hour;
		int minute;
	}

}
